import React, { Dispatch } from 'react';
import { AssetacquisitionManageAPI } from '../common/type';
import { FormInstance } from 'antd';

interface AcquisitionTableTypes {
  dataSource: Record<string, any>[]; //表格数据
  loading: boolean; // 加载
  mapList: Record<string, any>;
  assetForm: any; // 选中的资产信息表单
  pagination: Record<string, any>; //分页参数
  otherParams: Record<string, any>; //当前请求参数
  searchList: AssetacquisitionManageAPI.ISearchList;
  reloadTableData: () => void; // 重置
  [key: string]: any;
}

/**
 * Context 默认值类型
 */
type ManageContextTypes = {
  useReturnForm: FormInstance | any;
  rightTableProps: AcquisitionTableTypes; //表格数据参数
  curRes: Record<string, any>; // 权限
  acquisitionDispatch: Dispatch<any>; // 派发
  assetList: any; // 选中的资产列表
  materialList: any; // 选中的材料列表
  addAssetList: any;
};

/**
 * useContext
 * @rightTableProps 公共表格所需参数
 * @curRes 权限
 * @acquisitionDispatch reduce 派发器
 */
const INIT_ACQUISITIONMANAGE_CONTEXT: ManageContextTypes = {
  rightTableProps: {
    dataSource: [],
    assetForm: {},
    loading: false,
    getAcquisitionTableData: ({}) => {},
    mapList: [],
    pagination: {},
    otherParams: {},
    searchList: [],
    reloadTableData: () => {},
  },
  useReturnForm: {},
  assetList: [],
  materialList: [],
  addAssetList: [],
  curRes: {},
  acquisitionDispatch: () => {},
};

const AcquisitionManageContext = React.createContext(INIT_ACQUISITIONMANAGE_CONTEXT);

export { AcquisitionManageContext };
